package com.ruoyi.oos.web.controller.duty;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oos.duty.domain.DutyClasses;
import com.ruoyi.oos.duty.service.IDutyClassesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮值班次信息Controller
 * 
 * @author bulang
 * @date 2020-04-28
 */
@Controller
@RequestMapping("/duty/classes")
public class DutyClassesController extends BaseController
{
    private String prefix = "duty/classes";

    @Autowired
    private IDutyClassesService dutyClassesService;

    @RequiresPermissions("duty:classes:view")
    @GetMapping()
    public String classes()
    {
        return prefix + "/classes";
    }

        /**
     * 查询轮值班次信息列表
     */
    @RequiresPermissions("duty:classes:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DutyClasses dutyClasses)
    {
        startPage();
        List<DutyClasses> list = dutyClassesService.selectDutyClassesList(dutyClasses);
        return getDataTable(list);
    }
    
    /**
     * 导出轮值班次信息列表
     */
    @RequiresPermissions("duty:classes:export")
    @Log(title = "轮值班次信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DutyClasses dutyClasses)
    {
        List<DutyClasses> list = dutyClassesService.selectDutyClassesList(dutyClasses);
        ExcelUtil<DutyClasses> util = new ExcelUtil<DutyClasses>(DutyClasses.class);
        return util.exportExcel(list, "classes");
    }

    /**
     * 新增轮值班次信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存轮值班次信息
     */
    @RequiresPermissions("duty:classes:add")
    @Log(title = "轮值班次信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DutyClasses dutyClasses)
    {
        return toAjax(dutyClassesService.insertDutyClasses(dutyClasses));
    }

    /**
     * 修改轮值班次信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DutyClasses dutyClasses = dutyClassesService.selectDutyClassesById(id);
        mmap.put("dutyClasses", dutyClasses);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮值班次信息
     */
    @RequiresPermissions("duty:classes:edit")
    @Log(title = "轮值班次信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DutyClasses dutyClasses)
    {
        return toAjax(dutyClassesService.updateDutyClasses(dutyClasses));
    }

    /**
     * 删除轮值班次信息
     */
    @RequiresPermissions("duty:classes:remove")
    @Log(title = "轮值班次信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dutyClassesService.deleteDutyClassesByIds(ids));
    }
}
